package com.ruoyi.system.service.msg.enricher;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.system.dto.ContractDTO;
import com.ruoyi.system.dto.convert.ContractMapStruct;
import com.ruoyi.system.entity.ContractDO;
import com.ruoyi.system.entity.ContractFile;
import com.ruoyi.system.entity.MsgPushTaskDO;
import com.ruoyi.system.enums.MsgTypeEnum;
import com.ruoyi.system.mapper.ContractFileMapper;
import com.ruoyi.system.mapper.ContractMapper;
import com.ruoyi.system.service.ContractFileService;
import com.ruoyi.system.service.ContractService;
import com.ruoyi.system.service.msg.MsgDetailEnricher;
import com.ruoyi.system.util.MsgAttachmentConverter;
import com.ruoyi.system.vo.H5MsgDetailVO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 合同签署消息详情丰富器
 * 用于丰富合同签署类型消息的详情信息，包括合同详情和合同附件
 *
 * @author ruoyi
 * @since 2024-01-01
 */
@Component
public class ContractSignMsgEnricher implements MsgDetailEnricher {

    @Resource
    private ContractService contractService;

    @Override
    public boolean supports(Integer msgType) {
        return Objects.equals(msgType, MsgTypeEnum.CONTRACT_SIGN.getCode());
    }

    @Override
    public void enrich(H5MsgDetailVO vo, MsgPushTaskDO task) {
        if (task.getBusinessId() == null || task.getBusinessId().trim().isEmpty()) {
            return;
        }
        try {
            // 1. 获取合同详情
            Long contractId = Long.valueOf(task.getBusinessId());
            ContractDTO contract = contractService.getById(contractId);
            vo.setContract(contract);
        } catch (Exception e) {
            // 记录日志但不影响主流程
            System.err.println("获取合同签署信息时发生异常: " + e.getMessage());
        }
    }
}


